#include "./MiddlewareChain.h"

void MiddlewareChain::addMiddleware(std::shared_ptr<Middleware> middleware)
{
    this->middlewares_.push_back(middleware);
}

void MiddlewareChain::processBefore(HttpRequest &request)
{
    for (auto &middleware : this->middlewares_)
    {
        middleware->before(request);
    }
}

void MiddlewareChain::processAfter(HttpResponse &response)
{
    for (auto it = this->middlewares_.rbegin(); it != this->middlewares_.rend(); ++it)
    {
        (*it)->after(response);
    }
}